package com.tepth.maintenancesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tepth.maintenancesystem.R;
import com.tepth.maintenancesystem.bean.MaintainListWork;
import com.tepth.maintenancesystem.untils.Untils;

import java.util.List;

/**
 * Created by maning on 16/1/25.
 */
public class MaintainCompletedLeftAdapter extends BaseAdapter {

    private List<MaintainListWork> mDatas;
    private Context mContext;
    private LayoutInflater layoutInflater;
    private int mPosition;

    public MaintainCompletedLeftAdapter(Context mContext, List<MaintainListWork> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
        layoutInflater = LayoutInflater.from(this.mContext);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.maintain_details_left_item, parent, false);
            viewHolder.tv_left_details = (TextView) convertView.findViewById(R.id.tv_left_details);
            viewHolder.linear_left_details= (LinearLayout) convertView.findViewById(R.id.linear_left_details);
            viewHolder.tv_left_name= (TextView) convertView.findViewById(R.id.tv_left_name);
            viewHolder.tv_left_details_number= (TextView) convertView.findViewById(R.id.tv_left_details_number);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (mPosition == position) {
            viewHolder.linear_left_details.setBackgroundColor(Untils.getColor(mContext,R.color.colorSecondItemBackground));
            viewHolder.tv_left_details.setTextColor(Untils.getColor(mContext,R.color.colorItemTextRed));
        } else {
            viewHolder.linear_left_details.setBackgroundColor(Untils.getColor(mContext,R.color.colorFirstItemBackground));
            viewHolder.tv_left_details.setTextColor(Untils.getColor(mContext,R.color.colorItemTextBlack));
        }
        MaintainListWork obj=mDatas.get(position);
        viewHolder.tv_left_details.setText(obj.getContentTypeName());
        if(obj.getTemp_select_number()==0){
            viewHolder.tv_left_details_number.setVisibility(View.GONE);
        }else{
            viewHolder.tv_left_details_number.setVisibility(View.VISIBLE);
            viewHolder.tv_left_details_number.setBackground(Untils.getDrawable(mContext,R.drawable.design_doing_point));
            viewHolder.tv_left_details_number.setTextColor(Untils.getColor(mContext,R.color.white));
            viewHolder.tv_left_details_number.setText(obj.getTemp_select_number()+"");
        }
        viewHolder.tv_left_name.setVisibility(View.GONE);
//        if(obj.getConfirmPersonName().equals("null")||obj.getConfirmPersonName().equals("")){
//
//        }else{
//            viewHolder.tv_left_name.setVisibility(View.VISIBLE);
//            viewHolder.tv_left_name.setText(obj.getConfirmPersonName());
//        }
        return convertView;
    }

    public void setSelectPosition(int position) {
        mPosition = position;
    }

    public MaintainListWork getCurrentPositionItem() {
        return mDatas.get(mPosition);
    }

    private static class ViewHolder {
        TextView tv_left_details,tv_left_details_number,tv_left_name;
        LinearLayout linear_left_details;
    }

}
